import ExternalGlobals from 'rollup-plugin-external-globals'

export default {
  emptyOutDir: true,
  minify: 'terser',
  terserOptions: {
    compress: {
      drop_console: true,
      drop_debugger: true,
    },
  },
  rollupOptions: {
    output: {
      chunkFileNames: 'js/[name]-[hash].js',
      entryFileNames: 'js/[name]-[hash].js',
      assetFileNames: '[ext]/[name]-[hash].[ext]',
      manualChunks(id) {
        const moduleMap = {
          'node_modules/vuedraggable': 'vuedraggable',
          'node_modules/modern-screenshot': 'modern-screenshot',
          'node_modules/xlsx': 'xlsx',
          'node_modules/vue-pdf-embed': 'vue-pdf-embed',
        }

        for (const [key, value] of Object.entries(moduleMap)) {
          if (id.includes(key)) {
            return value
          }
        }
        if (id.includes('node_modules')) {
          return id
            .toString()
            .split('node_modules/')[1]
            .split('/')[0]
            .toString()
        }
      },
    },
    external: ['@wangeditor/editor'],
    plugins: [
      ExternalGlobals({
        // vue: 'vue',
        '@wangeditor/editor': 'wangEditor',
        // '@element-plus/icons-vue': 'ElementPlusIconsVue',
      }),
    ],
  },
}
